package ru.urfc.portal;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;

public class Utils {

	public static Date truncToDate(Date date) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.HOUR_OF_DAY, 0);
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);
		calendar.set(Calendar.MILLISECOND, 0);
		return calendar.getTime();
	}
	
    public static void copyStream(InputStream source, OutputStream dest) throws IOException {
        if (source == null) {
            return;
        }
        byte[] buffer = new byte[512];
        int nRead = source.read(buffer);
        while (nRead > 0) {
            dest.write(buffer, 0, nRead);
            nRead = source.read(buffer);
        }
    }
	
}
